home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cc02.arc
/
CPFILE.C
< prev
next >
Wrap
Text File
|
1986-03-14
|
931b
|
61 lines
/* -- cpfile.c copies from first file to second file <byte by byte> -- */
#include "stdio.h"
main(argc, argv) /* copy file a byte at a time */
int argc;
char *argv[];
{
int c;
FILE *infile, *outfile;
if (argc < 3)
errexit("Usage: cpfile oldfile newfile", NULL);
if (strcmp(argv[1], argv[2]) == 0)
errexit("File names must be different", NULL);
if ((infile = fopen(argv[1], "r")) == NULL)
errexit("Can't open", argv[1]);
if ((outfile = fopen(argv[2], "w")) == NULL)
errexit("Can't create", argv[2]);
printf("File %s ", argv[1]);
while ((c = getc(infile)) != EOF)
putc(c, outfile);
fclose(infile);
fclose(outfile);
printf("copied to %s\n", argv[2]);
exit(0);
}
errexit(s1, s2) /* print error message and die */
char *s1, *s2;
{
printf(s2 == NULL ? "%s\n" : "%s %s\n", s1, s2);
exit(-1);
}